{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script><script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window._Plotly) {require(['plotly'],function(plotly) {window._Plotly=plotly;});}</script>"
      ],
      "text/vnd.plotly.v1+html": [
       "<script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script><script type=\"text/javascript\">if (window.MathJax) {MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script><script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window._Plotly) {require(['plotly'],function(plotly) {window._Plotly=plotly;});}</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import plotly\n",
    "import plotly.graph_objs as go\n",
    "import numpy as np\n",
    "plotly.offline.init_notebook_mode(connected=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Basic Box Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "linkText": "Export to plot.ly",
        "plotlyServerURL": "https://plot.ly",
        "showLink": true
       },
       "data": [
        {
         "type": "box",
         "uid": "56d15fca-a9ac-4293-9f60-f247d664da32",
         "y": [
          1.0339397830007564,
          -1.4173444497954462,
          -0.6070876057406958,
          0.28268677288468336,
          -1.5247995332171327,
          -1.8096042168995483,
          -0.6324327777951443,
          -0.3375504795295271,
          -1.615444643209294,
          -1.5674650819767295,
          -0.05167273262967975,
          0.19066384570549255,
          -1.716706131748142,
          -2.6027140027213758,
          -2.7794475093915536,
          -1.0633992118945768,
          -1.7823261860502488,
          -0.49946672554497173,
          -3.0936737830622305,
          0.11338627420399461,
          -1.5084864248811527,
          0.7952111254614838,
          0.14366433638949627,
          -1.0423258223957919,
          0.06827807146408005,
          1.1460746777409496,
          -0.8644067404684217,
          -2.187499820565881,
          -3.5844198195229677,
          -1.110070847406223,
          -0.6254477641954751,
          1.297319388114735,
          -1.8384686966445352,
          -3.38294071756488,
          -3.249810887030475,
          -0.5133500389078889,
          -1.3644311972648717,
          -0.34352939411764793,
          -1.096049284284127,
          -0.4234032523219948,
          -1.2448012738968122,
          -1.5306717174785198,
          -2.670833520363942,
          -0.7945802959699577,
          -0.023355698360847832,
          -1.5620178622977807,
          -0.5065841290662005,
          -2.8231129340715064,
          -0.6090574067098771,
          -1.4769710329084889
         ]
        },
        {
         "type": "box",
         "uid": "1a6e9d58-281d-45ab-84df-c9ab8f8a917e",
         "y": [
          1.3047535901062441,
          -0.08379620656398479,
          -0.006647672426996154,
          2.3911122302917227,
          -0.3791786796298735,
          -0.021640457566409532,
          1.2973817897320743,
          2.781549236492273,
          0.3378772645254914,
          -0.41872691772447834,
          1.2289098964222451,
          2.201658847693984,
          -1.3074723357082343,
          1.5629865643893859,
          1.9384490712099702,
          2.1108975568607686,
          0.2284913591629938,
          1.2323322857272831,
          1.1582643638049248,
          0.7525744906181078,
          2.2393931875575928,
          1.1496072213193245,
          0.1773115144672449,
          0.405371522304143,
          0.9386835262917638,
          2.5614977786358137,
          1.1146056996297042,
          -1.0552001564407774,
          1.9888130220488072,
          -0.30055451511689446,
          1.6680284923489301,
          0.33367132599842186,
          0.47239992597044733,
          0.8524558422291666,
          1.0058898700280248,
          2.153770399058179,
          0.09425763050656244,
          -0.0611866187039527,
          0.5582468709314331,
          0.3923224996417254,
          -0.5102813277875677,
          1.6358853947091139,
          1.144888293061068,
          1.1412587331494195,
          2.1641816573609463,
          1.6028173644888515,
          0.30677342611139746,
          -0.2529723758098119,
          2.0376838961028687,
          1.851334012278981
         ]
        }
       ],
       "layout": {}
      },
      "text/html": [
       "<div id=\"ec8b6000-31b8-44dd-91aa-7fde05dbe992\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"ec8b6000-31b8-44dd-91aa-7fde05dbe992\", [{\"y\": [1.0339397830007564, -1.4173444497954462, -0.6070876057406958, 0.28268677288468336, -1.5247995332171327, -1.8096042168995483, -0.6324327777951443, -0.3375504795295271, -1.615444643209294, -1.5674650819767295, -0.05167273262967975, 0.19066384570549255, -1.716706131748142, -2.6027140027213758, -2.7794475093915536, -1.0633992118945768, -1.7823261860502488, -0.49946672554497173, -3.0936737830622305, 0.11338627420399461, -1.5084864248811527, 0.7952111254614838, 0.14366433638949627, -1.0423258223957919, 0.06827807146408005, 1.1460746777409496, -0.8644067404684217, -2.187499820565881, -3.5844198195229677, -1.110070847406223, -0.6254477641954751, 1.297319388114735, -1.8384686966445352, -3.38294071756488, -3.249810887030475, -0.5133500389078889, -1.3644311972648717, -0.34352939411764793, -1.096049284284127, -0.4234032523219948, -1.2448012738968122, -1.5306717174785198, -2.670833520363942, -0.7945802959699577, -0.023355698360847832, -1.5620178622977807, -0.5065841290662005, -2.8231129340715064, -0.6090574067098771, -1.4769710329084889], \"type\": \"box\", \"uid\": \"5df7f765-56c8-4e7d-a3f9-f3acdd58ca0a\"}, {\"y\": [1.3047535901062441, -0.08379620656398479, -0.006647672426996154, 2.3911122302917227, -0.3791786796298735, -0.021640457566409532, 1.2973817897320743, 2.781549236492273, 0.3378772645254914, -0.41872691772447834, 1.2289098964222451, 2.201658847693984, -1.3074723357082343, 1.5629865643893859, 1.9384490712099702, 2.1108975568607686, 0.2284913591629938, 1.2323322857272831, 1.1582643638049248, 0.7525744906181078, 2.2393931875575928, 1.1496072213193245, 0.1773115144672449, 0.405371522304143, 0.9386835262917638, 2.5614977786358137, 1.1146056996297042, -1.0552001564407774, 1.9888130220488072, -0.30055451511689446, 1.6680284923489301, 0.33367132599842186, 0.47239992597044733, 0.8524558422291666, 1.0058898700280248, 2.153770399058179, 0.09425763050656244, -0.0611866187039527, 0.5582468709314331, 0.3923224996417254, -0.5102813277875677, 1.6358853947091139, 1.144888293061068, 1.1412587331494195, 2.1641816573609463, 1.6028173644888515, 0.30677342611139746, -0.2529723758098119, 2.0376838961028687, 1.851334012278981], \"type\": \"box\", \"uid\": \"cc9bf847-0a3a-49c6-ae47-2e268129e274\"}], {}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"ec8b6000-31b8-44dd-91aa-7fde05dbe992\"));});</script>"
      ],
      "text/vnd.plotly.v1+html": [
       "<div id=\"ec8b6000-31b8-44dd-91aa-7fde05dbe992\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"ec8b6000-31b8-44dd-91aa-7fde05dbe992\", [{\"y\": [1.0339397830007564, -1.4173444497954462, -0.6070876057406958, 0.28268677288468336, -1.5247995332171327, -1.8096042168995483, -0.6324327777951443, -0.3375504795295271, -1.615444643209294, -1.5674650819767295, -0.05167273262967975, 0.19066384570549255, -1.716706131748142, -2.6027140027213758, -2.7794475093915536, -1.0633992118945768, -1.7823261860502488, -0.49946672554497173, -3.0936737830622305, 0.11338627420399461, -1.5084864248811527, 0.7952111254614838, 0.14366433638949627, -1.0423258223957919, 0.06827807146408005, 1.1460746777409496, -0.8644067404684217, -2.187499820565881, -3.5844198195229677, -1.110070847406223, -0.6254477641954751, 1.297319388114735, -1.8384686966445352, -3.38294071756488, -3.249810887030475, -0.5133500389078889, -1.3644311972648717, -0.34352939411764793, -1.096049284284127, -0.4234032523219948, -1.2448012738968122, -1.5306717174785198, -2.670833520363942, -0.7945802959699577, -0.023355698360847832, -1.5620178622977807, -0.5065841290662005, -2.8231129340715064, -0.6090574067098771, -1.4769710329084889], \"type\": \"box\", \"uid\": \"5df7f765-56c8-4e7d-a3f9-f3acdd58ca0a\"}, {\"y\": [1.3047535901062441, -0.08379620656398479, -0.006647672426996154, 2.3911122302917227, -0.3791786796298735, -0.021640457566409532, 1.2973817897320743, 2.781549236492273, 0.3378772645254914, -0.41872691772447834, 1.2289098964222451, 2.201658847693984, -1.3074723357082343, 1.5629865643893859, 1.9384490712099702, 2.1108975568607686, 0.2284913591629938, 1.2323322857272831, 1.1582643638049248, 0.7525744906181078, 2.2393931875575928, 1.1496072213193245, 0.1773115144672449, 0.405371522304143, 0.9386835262917638, 2.5614977786358137, 1.1146056996297042, -1.0552001564407774, 1.9888130220488072, -0.30055451511689446, 1.6680284923489301, 0.33367132599842186, 0.47239992597044733, 0.8524558422291666, 1.0058898700280248, 2.153770399058179, 0.09425763050656244, -0.0611866187039527, 0.5582468709314331, 0.3923224996417254, -0.5102813277875677, 1.6358853947091139, 1.144888293061068, 1.1412587331494195, 2.1641816573609463, 1.6028173644888515, 0.30677342611139746, -0.2529723758098119, 2.0376838961028687, 1.851334012278981], \"type\": \"box\", \"uid\": \"cc9bf847-0a3a-49c6-ae47-2e268129e274\"}], {}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"ec8b6000-31b8-44dd-91aa-7fde05dbe992\"));});</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "_0 = np.random.randn(50)-1\n",
    "_1 = np.random.randn(50)+1\n",
    "\n",
    "# X轴\n",
    "# trace0 = go.Box(x=_0)\n",
    "# trace1 = go.Box(x=_1)\n",
    "\n",
    "# Y轴\n",
    "trace0 = go.Box(y=_0)\n",
    "trace1 = go.Box(y=_1)\n",
    "\n",
    "data = [trace0, trace1]\n",
    "plotly.offline.iplot(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Grouped Box Plots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "linkText": "Export to plot.ly",
        "plotlyServerURL": "https://plot.ly",
        "showLink": true
       },
       "data": [
        {
         "marker": {
          "color": "#3D9970"
         },
         "name": "kale",
         "type": "box",
         "uid": "56712f3e-4ad3-4bd3-8431-b303ef80e57e",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.2,
          0.2,
          0.6,
          1,
          0.5,
          0.4,
          0.2,
          0.7,
          0.9,
          0.1,
          0.5,
          0.3
         ]
        },
        {
         "marker": {
          "color": "#FF4136"
         },
         "name": "radishes",
         "type": "box",
         "uid": "8e0ad046-cd41-444e-a31d-38ac6e7aeb19",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.6,
          0.7,
          0.3,
          0.6,
          0,
          0.5,
          0.7,
          0.9,
          0.5,
          0.8,
          0.7,
          0.2
         ]
        },
        {
         "marker": {
          "color": "#FF851B"
         },
         "name": "carrots",
         "type": "box",
         "uid": "b1d35981-36a2-4683-81f3-9767fa9db745",
         "x": [
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 1",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2",
          "day 2"
         ],
         "y": [
          0.1,
          0.3,
          0.1,
          0.9,
          0.6,
          0.6,
          0.9,
          1,
          0.3,
          0.6,
          0.8,
          0.5
         ]
        }
       ],
       "layout": {
        "boxmode": "group",
        "yaxis": {
         "title": "normalized moisture",
         "zeroline": false
        }
       }
      },
      "text/html": [
       "<div id=\"b290db81-88e0-4573-9a2f-9f4f0c632f82\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"b290db81-88e0-4573-9a2f-9f4f0c632f82\", [{\"marker\": {\"color\": \"#3D9970\"}, \"name\": \"kale\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3], \"type\": \"box\", \"uid\": \"56712f3e-4ad3-4bd3-8431-b303ef80e57e\"}, {\"marker\": {\"color\": \"#FF4136\"}, \"name\": \"radishes\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2], \"type\": \"box\", \"uid\": \"8e0ad046-cd41-444e-a31d-38ac6e7aeb19\"}, {\"marker\": {\"color\": \"#FF851B\"}, \"name\": \"carrots\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5], \"type\": \"box\", \"uid\": \"b1d35981-36a2-4683-81f3-9767fa9db745\"}], {\"boxmode\": \"group\", \"yaxis\": {\"title\": \"normalized moisture\", \"zeroline\": false}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"b290db81-88e0-4573-9a2f-9f4f0c632f82\"));});</script>"
      ],
      "text/vnd.plotly.v1+html": [
       "<div id=\"b290db81-88e0-4573-9a2f-9f4f0c632f82\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"b290db81-88e0-4573-9a2f-9f4f0c632f82\", [{\"marker\": {\"color\": \"#3D9970\"}, \"name\": \"kale\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3], \"type\": \"box\", \"uid\": \"56712f3e-4ad3-4bd3-8431-b303ef80e57e\"}, {\"marker\": {\"color\": \"#FF4136\"}, \"name\": \"radishes\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2], \"type\": \"box\", \"uid\": \"8e0ad046-cd41-444e-a31d-38ac6e7aeb19\"}, {\"marker\": {\"color\": \"#FF851B\"}, \"name\": \"carrots\", \"x\": [\"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 1\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\", \"day 2\"], \"y\": [0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5], \"type\": \"box\", \"uid\": \"b1d35981-36a2-4683-81f3-9767fa9db745\"}], {\"boxmode\": \"group\", \"yaxis\": {\"title\": \"normalized moisture\", \"zeroline\": false}}, {\"showLink\": true, \"linkText\": \"Export to plot.ly\", \"plotlyServerURL\": \"https://plot.ly\"})});</script><script type=\"text/javascript\">window.addEventListener(\"resize\", function(){window._Plotly.Plots.resize(document.getElementById(\"b290db81-88e0-4573-9a2f-9f4f0c632f82\"));});</script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']\n",
    "\n",
    "trace0 = go.Box(\n",
    "    y=[0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],\n",
    "    x=x,\n",
    "    name='kale',\n",
    "    marker=dict(color='#3D9970')\n",
    ")\n",
    "trace1 = go.Box(\n",
    "    y=[0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],\n",
    "    x=x,\n",
    "    name='radishes',\n",
    "    marker=dict(color='#FF4136')\n",
    ")\n",
    "trace2 = go.Box(\n",
    "    y=[0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5],\n",
    "    x=x,\n",
    "    name='carrots',\n",
    "    marker=dict(color='#FF851B')\n",
    ")\n",
    "\n",
    "data = [trace0, trace1, trace2]\n",
    "layout = go.Layout(\n",
    "    yaxis=dict(\n",
    "        title='normalized moisture',\n",
    "        zeroline=False\n",
    "    ),\n",
    "    boxmode='group'\n",
    ")\n",
    "fig = go.Figure(data=data, layout=layout)\n",
    "plotly.offline.iplot(fig)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
